//SPDX-License-Identifier: UNLICENSED pragma solidity >=0.6; contract purchase{ address public shipper; address payable private seller; address payable private buyer; uint public proposalTime; uint public status; // 0 is Start, 1 is Paid, 2 is Shipped constructor (address s) { shipper = s; // the seller must indicate who is the shipper now, otherwise later he might cheat and indicate himself as shipper seller = payable(msg.sender); // this identifies the sender, to give him the money status = 0; } function propose_and_pay() payable public{ require(status==0); // this blocks other users from making proposals (for simplicity, one purchase at the time) buyer=payable(msg.sender); // this identifies the buyer, to give back the mondey in case status = 1; proposalTime = block.timestamp; // let's remember the time to start the clock } function getContractBalance() view public returns(uint){ return address(this).balance; } function accept_and_ship() public{ require(msg.sender==seller); require(status==1); status=2; // we change the status so the shipper can now decide what is happening } function reject() public{ require(msg.sender==seller); require(status==1); status=0; buyer.transfer(address(this).balance); // money sent back to buyter because the seller does not want to go on } function delivered() public{ require(msg.sender==shipper); require(status==2); status=0; // purchase ends and we are ready for another purchase seller.transfer(address(this).balance); // money sent to seller } function not_delivered() public{ require(msg.sender==shipper); require(status==2); status=0; // purchase ends and we are ready for another purchase buyer.transfer(address(this).balance); // money sent back to buyer } function reclaim() public{ // too much time has passed require(msg.sender==buyer); // only the buyer can request money back require(status==2 || status==1); require(block.timestamp >= proposalTime + 40); // 40 seconds must have passed status=0; // purchase ends and we are ready for another purchase buyer.transfer(address(this).balance); // money sent back to buyer } }